package com.example.myapplication.movie;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.myapplication.Config.Commom;
import com.example.myapplication.Config.OKHttpTool;
import com.example.myapplication.Config.TokenBean;
import com.example.myapplication.R;
import com.example.myapplication.ShuJu.MoviedetailsBean;

public class MoviedetailsActivity extends AppCompatActivity {

    private String msvieinID;
    private ImageView but_lawyerList;
    private TextView name;
    private TextView score;
    private TextView playDate;
    private TextView likeNum;
    private String   TAG = "TAG";
    private ImageView img;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_moviedetails);
        Intent intent = getIntent();
        msvieinID = intent.getStringExtra(Commom.MSVIEIN_ID);
        Log.e(TAG,"msvieinID==>"+msvieinID);
        initview();
        //返回
        but_bloak();
        //获取详情
        sendmoviedetails();
    }

    private void sendmoviedetails() {
        OKHttpTool.doNetRequest("prod-api/api/movie/film/detail/" + msvieinID,
                OKHttpTool.GET,
                MoviedetailsBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                MoviedetailsBean moviedetailsBean =(MoviedetailsBean)obj;
                                MoviedetailsBean.DataBean data = moviedetailsBean.getData();
                                if(moviedetailsBean.getCode()==200){
                                    name.setText(data.getName());
                                    score.setText(String.valueOf(data.getScore()));
                                    playDate.setText(data.getPlayDate());
                                    likeNum.setText(String.valueOf(data.getLikeNum()));
                                    Glide.with(MoviedetailsActivity.this).load(TokenBean.IP+data.getCover()).into(img);
                                }
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {

                    }
                });
    }

    private void but_bloak() {
        but_lawyerList.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MoviedetailsActivity.this.finish();
            }
        });
    }


    private void initview() {
        but_lawyerList = findViewById(R.id.but_lawyerList);
        name = findViewById(R.id.name);
        score = findViewById(R.id.score);
        playDate = findViewById(R.id.playDate);
        likeNum = findViewById(R.id.likeNum);
        img = findViewById(R.id.img);
    }
}